home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3328 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.4 KB

  1. Path: news.usa.net!earth!jhamp
  2. From: jhamp@earth.usa.net (James Hamp)
  3. Newsgroups: comp.lang.c
  4. Subject: newbie--what's wrong with this?
  5. Date: 27 Jan 1996 22:21:08 GMT
  6. Organization: Internet Express (800-592-1240 customer service)
  7. Message-ID: <4ee8gk$kes@shiva.usa.net>
  8. NNTP-Posting-Host: earth.usa.net
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11. As a new C programmer, I'm sure I'm being dumb, but I don't know what I 
  12. did wrong.
  13.  
  14. Basically, I have an array of structs called MESSAGERULES, which contain 
  15. a pointer to a set of RULES to apply to a message, which in turn contain 
  16. a pointer to COMPARERULES, with the whole object being to see if a message
  17. matches one of the RULES in the set by comparing it in turn to each of the
  18. COMPARERULES.
  19.  
  20. In initializing these, I used the following code (not on this machine, so 
  21. I can't use cut/paste--if you see any compile errors, they're typos.
  22.  
  23.  
  24. MSGRULE MsgRule[];
  25. RULE *Rule;
  26.  
  27. /* Some initializations of MsgRule */
  28.  
  29. MsgRule[offset].Rule = (RULE *)malloc(2 * sizeof(RULE));
  30.  
  31. /* Some more inititalizations of MsgRule.Rule
  32.  
  33. Rule = MsgRule[offset].Rule;  /* Just to save typing--had to use this 
  34.                                  several times   */
  35.  
  36. Rule->CompRule = (COMPARERULE *)malloc(2 * sizeof(COMPARERULE));
  37.  
  38. /* Initialize first compare rule, then... */
  39.  
  40. Rule->CompRule++;
  41. ^^^^^^^^^^^^^^^^^   This didn't work--when I initialized the second rule
  42.                     (or so I thought), it went into the first rule.
  43.  
  44. Thinking I had a precedence problem, I tried
  45.  
  46. (Rule->CompRule)++;
  47.  
  48. and the same thing happened.
  49. I know I'm being stupid here--my try that worked was
  50. to initialize the second rule with Rule->CompRule[1].members.  Since I 
  51. made it work, the code's okay, but I'd like to know what I'm not under-
  52. standing.  Please e-mail responses--I don't get to this group as often
  53. as I'd like.
  54.  
  55. advTHANKSance
  56. --Jim (The Hampster) Hamp
  57. |*************************************************************************|
  58. |  So you ride yourselves over the fields                                 |
  59. |  And you make all your animal deals                   This space        |
  60. |  And your wise men don't know how it feels            for rent.         |
  61. |  To be thick as a brick                                                 |
  62. |  -Ian Anderson-                                       The Hampster      |
  63. |                                                       jhamp@usa.net     |
  64. |*************************************************************************|
  65.